extends CardState

var mouse_over_card := false

func enter() -> void:
	if not card_ui.is_node_ready():
		await card_ui.ready
		
	if card_ui.tween and card_ui.tween.is_running():
		card_ui.tween.kill()
	card_ui.card_visuals.panel.add_theme_stylebox_override("panel", AutoLoader.BASE_STYLEBOX)
	card_ui.do_reparent(card_ui)
	card_ui.pivot_offset=Vector2.ZERO
	Events.do_tooltip_hide()

func on_gui_input(event: InputEvent) -> void:
	if card_ui.disable or not card_ui.playable:
		return
	if mouse_over_card and event.is_action_pressed("left_mouse"):
		card_ui.pivot_offset = card_ui.get_global_mouse_position() - card_ui.global_position
		do_transition(self, CardState.State.CLICKED)

func on_mouse_entered() -> void:
	mouse_over_card = true
	if card_ui.disable or not card_ui.playable:
		return
	card_ui.card_visuals.panel.add_theme_stylebox_override("panel", AutoLoader.HOVER_STYLEBOX)
	card_ui.request_tooltip()
	
func on_mouse_exited() -> void:
	mouse_over_card = false
	if card_ui.disable or not card_ui.playable:
		return
	card_ui.card_visuals.panel.add_theme_stylebox_override("panel", AutoLoader.BASE_STYLEBOX)
	Events.do_tooltip_hide()
